function [ time, P ] = Spectral_Perm( C, d, K )

[N, ~] = size(C);
n = N/d;

time_start = tic;
[P,~] = eigs(C,d);

OptO = P;
OptV = -Inf;
for sample = 1:K
    randO = unirandO(d);
    for i = 1:n
        X = -P( (i-1)*d+1:i*d , : ) * randO;
        [assignment, ~] = assignmentoptimal(X);
        A = zeros(d);
        A((1:d)'+(assignment-1)*d) = 1;
        P( (i-1)*d+1:i*d , : ) = A;
    end
    
end
    


P = P*P(1:d,:)';

time = toc(time_start);

end

